package org.darkforest.admin.controller;

import org.darkforest.annotation.ArchivesLog;
import org.darkforest.common.services.FestivalService;
import org.darkforest.common.util.DateUtil;
import org.darkforest.dao.mapper.FestivalMapper;
import org.darkforest.model.Festival;
import org.darkforest.vo.MemberBase;
import org.darkforest.vo.StoreSellerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 节日管理
 * Created by Administrator on 2017/4/5.
 */
@Controller
@RequestMapping(value = "festival")
public class FestivalController {
    @Autowired
    private FestivalMapper festivalMapper;
    @Autowired
    private FestivalService festivalService;
    @RequestMapping(value = "list")
    public ModelAndView festivalList(Festival festival){
        ModelAndView res = new ModelAndView("setting/festival/list");
        festival.setResultList(festivalMapper.selectListByCondition(festival));
        res.addObject("page",festival);
        return res;
    }

    @RequestMapping(value = "toadd")
    public ModelAndView toAdd() {
        ModelAndView view = new ModelAndView("setting/festival/add");
        return view;
    }

    @RequestMapping(value = "doadd")
    @ArchivesLog(operationDescription = "新增节日")
    public String doAdd(Festival festival, HttpServletRequest request) {
        MemberBase memberBase = (MemberBase)request.getSession().getAttribute("memInfo");
        festival.setCreaterId(memberBase.getUserId());
        festival.setCreateName(memberBase.getUserName());
        festival.setCreateTime(DateUtil.toTimeString(new Date()));
        festivalMapper.insertSelective(festival);
        return "redirect:list";
    }

    @RequestMapping(value = "toedit")
    public ModelAndView toEdit(Integer id) {
        ModelAndView view = new ModelAndView("setting/festival/edit");
        Festival festival = festivalMapper.selectByPrimaryKey(id);
        view.addObject("festival", festival);
        return view;
    }

    @RequestMapping(value = "doedit")
    @ArchivesLog(operationDescription = "修改节日")
    public String doEdit(Festival festival,HttpServletRequest request) {
        MemberBase memberBase = (MemberBase)request.getSession().getAttribute("memInfo");
        festival.setCreaterId(memberBase.getUserId());
        festival.setCreateName(memberBase.getUserName());
        festival.setCreateTime(DateUtil.toTimeString(new Date()));
        festivalMapper.updateByPrimaryKeySelective(festival);
        return "redirect:list";
    }

    @RequestMapping(value = "todel")
    @ArchivesLog(operationDescription = "删除节日")
    public String todel(Integer id) {
        festivalService.deleteFandFR(id);
        return "redirect:list";
    }

}
